var interfaceAddress = "http://qqt.qingqingting.com.cn";

// 电话检测
function checkTelephone(openid) {
	$.ajax({
		type : "GET",
		url : "openid/ajax.php?fn=getPhoneByOpenId",
		data : {
			"openid" : openid
		},
		dataType : "html",
		success : function(data) {
			data = $.parseJSON(data)
			if (data.result) {
				var phone = data.phone;
				webChatSubmitInfo(phone);
			}
		},
		error : function() {
			alert("请求失败");
		}
	});
}

// 电话检测
function saveTelephone(openid, phone) {
	$.ajax({
		type : "GET",
		url : "openid/ajax.php?fn=save",
		data : {
			"openid" : openid,
			"phone" : phone
		},
		dataType : "html",
		success : function(data) {
			data = $.parseJSON(data)
			if (!data.result) {
				alert("插入失败");
			}
		},
		error : function() {
			alert("请求失败");
		}
	});
}

function checkOrLink(phone) {
	if (phone && 0 < phone.length) {
		var info = locationMsg.split("|");
		var lng = info[0];
		var lat = info[1];
		var zoom = info[2];
		location.href = interfaceAddress + "/peripheralInterface/webChatSubmitInfo.do?map=" + (lng + "|" + lat + "|" + zoom) + "&mobilePhone=" + phone + "&name=" + phone + "&openid=" + openid;
	} else {
		location.href = "Tel.php?location=" + locationMsg + "&openid=" + openid;
	}
}

function webChatSubmitInfo(phone) {
	var telephone = phone;
	var info = locationMsg.split("|");
	var lng = info[0];
	var lat = info[1];
	var zoom = info[2];
	$.ajax({
		type : "POST",
		url : interfaceAddress + "/peripheralInterface/submitInfo.do",
		data : "{'map':'" + (lng + "|" + lat + "|" + zoom) + "', 'mobilePhone':'" + telephone + "','name':'" + telephone + "'}",
		dataType : "json",
		success : function(data) {
			if (data.result) {
				location.href = "Iknow.php?location=" + locationMsg + "&openid=" + openid;
			} else {
				alert(data.msg);
			}
		},
		error : function() {
			// alert("请求失败");
			// navigator.notification.alert("请求失败", function() {
			// }, '提示', '确认');
			alert("请求失败");
		}
	});
}